//
//  BLEAutoTestVC.swift
//  SDKDebuggingDemo
//
//  Created by 秦晟哲 on 2019/9/5.
//  Copyright © 2019 QinszQSZ. All rights reserved.
//

import UIKit

class BLEAutoTestVC: UIViewController {
    
    @IBOutlet weak var switcher: UISwitch!
    private var taskArray = Array<KCTOldBLETaskBase>.init()

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
        KCTSingleBLEShell.sharedInstance.globalOldTaskTimeout = 30.0
        
        KCTSingleBLEShell.sharedInstance.asyncEnable = switcher.isOn

        
        let readFirmware = KCTOldBLETaskReadFirmwareInfos.init { (tsk, error, infos) in
            IPrint(ResultContent(title: "获取固件信息", error: error, rspDes: "\(infos?.yy_modelToJSONObject() ?? "")"))
        }
        taskArray.append(readFirmware)
        
        let readSettings = KCTOldBLETaskReadSettings.init { (tsk, error, settings) -> (Void) in
            IPrint(ResultContent(title: "获取设置信息", error: error, rspDes: "\(settings?.yy_modelToJSONObject() ?? "")"))

        }
        taskArray.append(readSettings)
        
        let syncSport = KCTOldBLETaskSyncSport.init(date: KCTBLEDate.init(date: Date.init())) { (tsk, error, sports) in
            let ary = NSArray.init(array: sports)
            IPrint(ResultContent(title: "同步历史运动", error: error, rspDes: "\(ary.yy_modelToJSONObject() ?? "")"))
        }
        taskArray.append(syncSport)
        
        let realStep = KCTOldBLETaskSyncRealTimeSport.init { (tsk, info, error) in
            IPrint(ResultContent(title: "同步实时记步", error: error, rspDes: "\(info?.yy_modelToJSONObject() ?? "")"))
        }
        taskArray.append(realStep)
        let readProfile = KCTOldBLETaskReadProfile.init { (tsk, profile, error) -> (Void) in
            IPrint(ResultContent(title: "获取配置信息", error: error, rspDes: "\(profile?.yy_modelToJSONObject() ?? "")"))
        }
        taskArray.append(readProfile)
        
    }

    @IBAction func switchValueChange(_ sender: Any) {
        KCTSingleBLEShell.sharedInstance.asyncEnable = switcher.isOn
    }
    
    @IBAction func clickBack(_ sender: Any) {
        self.navigationController?.popViewController(animated: true)
    }
    @IBAction func clickStart(_ sender: Any) {
        
        for tsk in taskArray{
            KCTSingleBLEShell.sharedInstance.resume(baseTask: tsk)
        }
        
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
